@ECHO OFF

SET VSS_GET_LATEST=TRUE
SET COMPILE_SOLUTION=TRUE
SET SSUSER=build
SET SSPWD=frbbuilds
SET SSDIR=Y:\VSSFRB
SET BUILD_WORKSPACE=C:\BUILD_WORKSPACE
SET SSEXE=C:\Program Files\Microsoft Visual SourceSafe\ss.exe
SET DEVENV2005=C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv
SET DEVENV2008=C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv

REM RETRIEVE DATE FORMATTED YYYYMMDD
FOR /F "tokens=1-4 delims=/ " %%I IN ('DATE /t') DO SET MYDATE=%%L%%J%%K
FOR /F "tokens=1-2 delims=/:" %%A IN ("%TIME%") DO SET MYTIME=%%A%%B
FOR /F "tokens=1-2 delims=/ " %%A IN ("%MYTIME%") DO SET MYTIME=%%A

IF %MYTIME% LSS 1000 SET MYTIME=0%MYTIME%

SET MYDATETIME=%MYDATE%_%MYTIME%

ECHO .
ECHO *** YOU MUST FULL STOP THE FRB BIZTALK APPLICATIONS ***
ECHO .
PAUSE

ECHO .
ECHO *** REMOVING PREVIOUS BIZTALK APPLICATIONS ***
ECHO .

BTSTask RemoveApp -ApplicationName:"FRB Book Transfers"
BTSTask RemoveApp -ApplicationName:"FRB OSI"
BTSTask RemoveApp -ApplicationName:"FRB Wire Transfers"

"%SSEXE%" About

ECHO .
ECHO *** GETTING LATEST SOURCE ***
ECHO .

IF %VSS_GET_LATEST%==TRUE (
	RD /S /Q "%BUILD_WORKSPACE%"
	MD "%BUILD_WORKSPACE%"
	CD "%BUILD_WORKSPACE%"
	"%SSEXE%" workfold $/ "%BUILD_WORKSPACE%"
	"%SSEXE%" label $/ -L"BUILD_%MYDATETIME%" -CBuild
	"%SSEXE%" get $/ -R -Vl"BUILD_%MYDATETIME%
) ELSE (
	ECHO SKIPPED -- GET_LATEST=FALSE
)

ECHO .
ECHO *** CHECKING OUT MSI FILES ***
ECHO .

CD "%BUILD_WORKSPACE%\FRB.EagleConnect\Solution Items\Deployment"
"%SSEXE%" checkout "$/FRB.EagleConnect/Solution Items/Deployment/*.msi" -GWR -CBuild
CD "%BUILD_WORKSPACE%\FRB.EagleConnect - VS2008\Solution Items\Deployment"
"%SSEXE%" checkout "$/FRB.EagleConnect - VS2008/Solution Items/Deployment/*.msi" -GWR -CBuild

ECHO .
ECHO *** COMPILING SOLUTIONS ***
ECHO .

IF %COMPILE_SOLUTION%==TRUE (
	"%DEVENV2005%" "%BUILD_WORKSPACE%\FRB.EagleConnect\FRB.EagleConnect.sln" /Rebuild Deployment
	"%DEVENV2008%" "%BUILD_WORKSPACE%\FRB.EagleConnect - VS2008\FRB.EagleConnect - VS2008.sln" /Rebuild Deploy
) ELSE (
	ECHO SKIPPED -- COMPILE_SOLUTION=FALSE
)

ECHO .
ECHO *** CREATING NEW BIZTALK APPLICATION -- OSI ***
ECHO .

CD "%BUILD_WORKSPACE%\FRB.EagleConnect\Solution Items\Deployment"
BTSTask ImportApp -Package:"FRB OSI.msi" -ApplicationName:"FRB OSI" -Environment:"DEV" -Overwrite

ECHO .
ECHO *** ADDING BIZTALK RESOURCES -- OSI ***
ECHO .

BTSTask AddResource -ApplicationName:"FRB OSI" -Type:BizTalkBinding -Source:"%BUILD_WORKSPACE%\FRB.EagleConnect\FRB.EagleConnect.OSI.BizTalk.Artifacts\Bindings\FRB OSI.BindingInfo-DEV.xml" -Property:TargetEnvironment=DEV -Overwrite
BTSTask AddResource -ApplicationName:"FRB OSI" -Type:BizTalkBinding -Source:"%BUILD_WORKSPACE%\FRB.EagleConnect\FRB.EagleConnect.OSI.BizTalk.Artifacts\Bindings\FRB OSI.BindingInfo-PROD.xml" -Property:TargetEnvironment=PROD -Overwrite
BTSTask AddResource -ApplicationName:"FRB OSI" -Type:Assembly -Source:"%BUILD_WORKSPACE%\FRB.EagleConnect\FRB.EagleConnect.OSI.VcmMessages\bin\Release\FRB.EagleConnect.OSI.VcmMessages.dll" -Destination="%%BTAD_InstallDir%%\FRB.EagleConnect.OSI.VcmMessages.dll" -Options:GacOnImport,GacOnInstall -Overwrite
BTSTask AddResource -ApplicationName:"FRB OSI" -Type:BizTalkAssembly -Source:"%BUILD_WORKSPACE%\FRB.EagleConnect\FRB.EagleConnect.OSI.BizTalk.Artifacts\bin\Deployment\FRB.EagleConnect.OSI.BizTalk.Artifacts.dll" -Destination="%%BTAD_InstallDir%%\FRB.EagleConnect.OSI.BizTalk.Artifacts.dll" -Options:GacOnImport,GacOnInstall -Overwrite

ECHO .
ECHO *** CREATING NEW BIZTALK APPLICATION -- BOOK TRANSFERS ***
ECHO .

BTSTask ImportApp -Package:"FRB Book Transfers.msi" -ApplicationName:"FRB Book Transfers" -Environment:"DEV" -Overwrite

ECHO .
ECHO *** ADDING BIZTALK RESOURCES -- BOOK TRANSFERS ***
ECHO .

BTSTask AddResource -ApplicationName:"FRB Book Transfers" -Type:BizTalkBinding -Source:"%BUILD_WORKSPACE%\FRB.EagleConnect\FRB.EagleConnect.Transfers.Book.BizTalk.Artifacts\Bindings\FRB Book Transfers.BindingInfo-DEV.xml" -Property:TargetEnvironment=DEV -Overwrite
BTSTask AddResource -ApplicationName:"FRB Book Transfers" -Type:BizTalkBinding -Source:"%BUILD_WORKSPACE%\FRB.EagleConnect\FRB.EagleConnect.Transfers.Book.BizTalk.Artifacts\Bindings\FRB Book Transfers.BindingInfo-PROD.xml" -Property:TargetEnvironment=PROD -Overwrite
BTSTask AddResource -ApplicationName:"FRB Book Transfers" -Type:Assembly -Source:"%BUILD_WORKSPACE%\FRB.EagleConnect - VS2008\FRB.EagleConnect.AccountAccess.Data\bin\Deploy\FRB.EagleConnect.AccountAccess.Data.dll" -Destination="%%BTAD_InstallDir%%\FRB.EagleConnect.AccountAccess.Data.dll" -Options:GacOnImport,GacOnInstall -Overwrite
BTSTask AddResource -ApplicationName:"FRB Book Transfers" -Type:BizTalkAssembly -Source:"%BUILD_WORKSPACE%\FRB.EagleConnect\FRB.EagleConnect.Transfers.Book.BizTalk.Artifacts\bin\Deployment\FRB.EagleConnect.Transfers.Book.BizTalk.Artifacts.dll" -Destination="%%BTAD_InstallDir%%\FRB.EagleConnect.Transfers.Book.BizTalk.Artifacts.dll" -Options:GacOnImport,GacOnInstall -Overwrite

ECHO .
ECHO *** CREATING NEW BIZTALK APPLICATION -- WIRE TRANSFERS ***
ECHO .

BTSTask ImportApp -Package:"FRB Wire Transfers.msi" -ApplicationName:"FRB Wire Transfers" -Environment:"DEV" -Overwrite

ECHO .
ECHO *** ADDING BIZTALK RESOURCES -- WIRE TRANSFERS ***
ECHO .

BTSTask AddResource -ApplicationName:"FRB Wire Transfers" -Type:BizTalkBinding -Source:"%BUILD_WORKSPACE%\FRB.EagleConnect\FRB.EagleConnect.Transfers.Wire.BizTalk.Artifacts\Bindings\FRB Wire Transfers.BindingInfo-DEV.xml" -Property:TargetEnvironment=DEV -Overwrite
BTSTask AddResource -ApplicationName:"FRB Wire Transfers" -Type:BizTalkBinding -Source:"%BUILD_WORKSPACE%\FRB.EagleConnect\FRB.EagleConnect.Transfers.Wire.BizTalk.Artifacts\Bindings\FRB Wire Transfers.BindingInfo-PROD.xml" -Property:TargetEnvironment=PROD -Overwrite
BTSTask AddResource -ApplicationName:"FRB Wire Transfers" -Type:BizTalkAssembly -Source:"%BUILD_WORKSPACE%\FRB.EagleConnect\FRB.EagleConnect.Transfers.Wire.BizTalk.Artifacts\bin\Deployment\FRB.EagleConnect.Transfers.Wire.BizTalk.Artifacts.dll" -Destination="%%BTAD_InstallDir%%\FRB.EagleConnect.Transfers.Wire.BizTalk.Artifacts.dll" -Options:GacOnImport,GacOnInstall -Overwrite

ECHO .
ECHO *** IMPORTING LATEST BINDINGS ***
ECHO .

BTSTask ImportBindings -Source:"%BUILD_WORKSPACE%\FRB.EagleConnect\FRB.EagleConnect.OSI.BizTalk.Artifacts\Bindings\FRB OSI.BindingInfo-DEV.xml" -ApplicationName:"FRB OSI"
BTSTask ImportBindings -Source:"%BUILD_WORKSPACE%\FRB.EagleConnect\FRB.EagleConnect.Transfers.Book.BizTalk.Artifacts\Bindings\FRB Book Transfers.BindingInfo-DEV.xml" -ApplicationName:"FRB Book Transfers"
BTSTask ImportBindings -Source:"%BUILD_WORKSPACE%\FRB.EagleConnect\FRB.EagleConnect.Transfers.Wire.BizTalk.Artifacts\Bindings\FRB Wire Transfers.BindingInfo-DEV.xml" -ApplicationName:"FRB Wire Transfers"

ECHO .
ECHO *** EXPORTING BIZTALK MSI's ***
ECHO .

CD "%BUILD_WORKSPACE%\FRB.EagleConnect\Solution Items\Deployment"
BTSTask ExportApp -Package:"FRB OSI.msi" -ApplicationName:"FRB OSI"
BTSTask ExportApp -Package:"FRB Book Transfers.msi" -ApplicationName:"FRB Book Transfers"
BTSTask ExportApp -Package:"FRB Wire Transfers.msi" -ApplicationName:"FRB Wire Transfers"

ECHO .
ECHO *** CHECKING IN MSI FILES ***
ECHO .

CD "%BUILD_WORKSPACE%\FRB.EagleConnect\Solution Items\Deployment"
"%SSEXE%" checkin "$/FRB.EagleConnect/Solution Items/Deployment/*.msi" -CBuild
CD "%BUILD_WORKSPACE%\FRB.EagleConnect - VS2008\Solution Items\Deployment"
"%SSEXE%" checkin "$/FRB.EagleConnect - VS2008/Solution Items/Deployment/*.msi" -CBuild

ECHO .
ECHO *** BUILD OUTPUT PLACED IN BUILD_%MYDATETIME%
ECHO .
XCOPY /s/e/r/i/y "%BUILD_WORKSPACE%\FRB.EagleConnect\Solution Items\Deployment\*.msi" "%BUILD_WORKSPACE%\BUILD_%MYDATETIME%"
XCOPY /s/e/r/i/y "%BUILD_WORKSPACE%\FRB.EagleConnect - VS2008\Solution Items\Deployment\*.msi" "%BUILD_WORKSPACE%\BUILD_%MYDATETIME%"

REM not sure why these folders get created but get rid of them
RD /s/q "%BUILD_WORKSPACE%\BUILD_%MYDATETIME%\Visual Studio 2005Projects" 2>NUL
RD /s/q "%BUILD_WORKSPACE%\BUILD_%MYDATETIME%\Visual Studio 2008" 2>NUL

ECHO .
ECHO *** BUILD COMPLETE ***
ECHO .

GOTO END

:END
PAUSE
